package microcredit.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import microcredit.model.domain.MemberInactiveReason;
import microcredit.model.domain.Status;
import microcredit.model.util.ModelUtils;

/**
 * Entity implementation class for Entity: MemberStatusHistory
 *
 */
@Entity
public class MemberStatusHistory implements Serializable {

	private static final long serialVersionUID = 1L;

	public MemberStatusHistory() {
		super();
	}

	@Id
	@Column(name="MEMBER_ID", updatable=false, insertable=false)
	private Long memberID;
	
	@Id
	private Long sequenceID;
	
	@OneToOne()
	private Member member;
	
	@Enumerated(EnumType.STRING)
	@Column(length=1)
	private Status status;
	
	@Enumerated(EnumType.STRING)
	@Column(length=1)
	private MemberInactiveReason reason;
	
	@Column(length=5000)
	private String reasonText;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false)
	private Date insertStamp;


	@PrePersist
	public void prePersist() throws ValidationException {
		if (getInsertStamp() == null) {
			setInsertStamp(ModelUtils.createTimestamp());
		}
		validate();
	}
	
	@PreUpdate
	public void preUpdate() throws ValidationException {
		validate();
	}
	
	public void validate() throws ValidationException {
		//TODO a lot more validations necessary
	}
	
	public Long getMemberID() {
		return memberID;
	}

	public Long getSequenceID() {
		return sequenceID;
	}

	public void setSequenceID(Long sequenceID) {
		this.sequenceID = sequenceID;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public MemberInactiveReason getReason() {
		return reason;
	}

	public void setReason(MemberInactiveReason reason) {
		this.reason = reason;
	}

	public String getReasonText() {
		return reasonText;
	}

	public void setReasonText(String reasonText) {
		this.reasonText = reasonText;
	}

	public Date getInsertStamp() {
		return insertStamp;
	}

	public void setInsertStamp(Date insertStamp) {
		this.insertStamp = insertStamp;
	}
	
}
